unless defined?(RediPress)
  raise "You can't load this file. Please load the redipress file instead."
end

module RediPress
  # This class holds all paramaters required by a configuration.
  #
  class Parameter
    attr_reader :slug, :required, :options

    # Setup an instance of the parameters class.
    #
    # Arguments:
    #   slug: (String|Symbol)
    #
    # Example:
    #   >> RediPress::Parameter.new(:username)
    #   => #<RediPress::Parameter:0x00000000000000>
    #
    def initialize(slug)
      @slug = slug
      @name = slug.to_s
      @required = true
      @type = :text
    end

    # Set the name of the parameter
    #
    # Arguments:
    #   name: (String)
    #
    # Example:
    #   >> parameter.name("Username")
    #   => "Username"
    #
    def name(name = nil)
      name.nil? ? @name : @name = name
    end

    # Set the parameter to required
    #
    # Available With Types:
    #   :text
    #
    # Arguments:
    #   required: (Boolean)
    #
    # Example:
    #   >> parameter.required(true)
    #   => true
    #
    def required(required = nil)
      required.nil? ? @required : @required = required
    end

    # Set the type of the parameter
    #
    # Arguments:
    #   type: (Symbol)
    #
    # Example:
    #   >> parameter.type(:text)
    #   => :text
    #
    def type(type = nil)
      type.nil? ? @type : @type = type
    end

    # Set the default value
    #
    # Available With types:
    #   :text
    #
    # Arguments:
    #   default: (String)
    #
    # Example:
    #   >> parameter.default('rediwebhosting')
    #   => "rediwebhosting"
    #
    def default(default = nil)
      default.nil? ? @default : @default = default
    end

    # Set the validation regex
    #
    # Available With types:
    #   :text
    #
    # Arguments:
    #   validation: (Regex)
    #
    # Example:
    #   >> parameter.validation(/^[a-z]{4,}$/)
    #   => /^[a-z]{4,}$/
    #
    def validation(validation = nil)
      validation.nil? ? @validation : @validation = validation
    end

    # Add an option
    #
    # Available With types:
    #   :select
    #   :multi_select
    #
    # Arguments:
    #   option: (String)
    #
    # Example:
    #   >> parameter.option('rediweb')
    #   => nil
    #   >> parameter.option('rediwebhosting')
    #   => nil
    #
    def option(option)
      @options ||= []
      @options << option
      nil
    end
  end
end
